use axum::{
    extract::Query,
    Json,
};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Debug, Default)]
pub struct Blog {
    id: usize,
    title: String,
    content: String,
    author_id: usize,
    tags: Vec<String>,
    stars: usize,
}

#[derive(Serialize, Debug, Default)]
pub struct BlogBrief {
    id: usize,
    title: String,
    content: String,
}

#[derive(Serialize, Debug, Default)]
pub struct BlogsBrief {
    index: usize,
    count: usize,
    blogs_brief: Vec<BlogBrief>,
}

#[derive(Deserialize)]
pub struct BlogParams {
    id: usize,
}

pub async fn get_blog(params: Query<BlogParams>) -> Result<Json<Blog>, String> {
    dbg!("Getting blog: {}", params.id);

    Ok(Json(Blog {
        id: params.id,
        title: "Title".to_owned(),
        content: "Content".to_owned(),
        author_id: 1,
        tags: vec!["tag1".to_owned(), "tag2".to_owned()],
        stars: 10,
    }))
}

pub async fn get_blogs_brief() -> Result<Json<BlogsBrief>, String> {
    dbg!("Getting blogs brief");

    Ok(Json(BlogsBrief {
        index: 0,
        count: 5,
        blogs_brief: vec![
            BlogBrief {
                id: 1,
                title: "Title 1".to_owned(),
                content: "Content 1".to_owned(),
            },
            BlogBrief {
                id: 2,
                title: "Title 2".to_owned(),
                content: "Content 2".to_owned(),
            },
            BlogBrief {
                id: 3,
                title: "Title 3".to_owned(),
                content: "Content 3".to_owned(),
            },
            BlogBrief {
                id: 4,
                title: "Title 4".to_owned(),
                content: "Content 4".to_owned(),
            },
            BlogBrief {
                id: 5,
                title: "Title 5".to_owned(),
                content: "Content 5".to_owned(),
            },
        ],
    }))
}